define(['moment', 'module/system/service/WatchDogService'], function (moment) {
    return ['$scope', '$rootScope', '$filter', '$stateParams', '$mdDialog', 'config', 'MMWService', '$css', '$timeout', 'WatchDogService',
        function ($scope, $rootScope, $filter, $stateParams, $mdDialog, config, $MMWService, $css, $timeout, $WatchDogService) {
            var _refresh, dog, _condition = [];
            $scope.init = function () {
                $css.add('JSplugins/angular-gantt/angular-gantt.min.css');
                $css.add('JSplugins/angular-ui-tree/angular-ui-tree.min.css');
                $css.add('JSplugins/angular-gantt/angular-gantt-plugins.min.css');
                $css.add('JSplugins/angular-gantt/angular-gantt-progress-plugin.min.css');
                //$css.add('JSplugins/angular-gantt/angular-gantt-tooltips-plugin.min.css');
                $scope.searchConditionList = [];
                //$scope.queryMode = 'list';
                $scope.queryMode = 'list-gantt';
                $scope.showGanttPanel = false;
                $scope.options = {
                    orderBy: 'model.seq',
                    maxHeight: 0,
                    columnWidth: 28
                };
                _refresh = {
                    condition: [],
                    count: 0,
                    time: 60,
                    page_time: 30,
                    is_start: 'N',
                    page_count: 25,
                    line_height: 32,
                    font_size: 14
                };
                var _s_refresh = localStorage.getItem(config.appName + '_RPT_Settings_' + $scope.$root.currentState);
                if (_s_refresh) {
                    _refresh = angular.merge(_refresh, JSON.parse(_s_refresh));
                }
                _refresh.sleep = 0.2;
                _refresh.count = 0;

                dog = {
                    sleep: _refresh.sleep,
                    bark: function (feed, next) {
                        var _result_list = document.getElementById('panel_gantt');
                        if (_refresh.count >= _refresh.time) {
                            _refresh.count = 0;
                            $scope.search(_condition, next, false);
                        } else {
                            var _distance = Math.ceil((_result_list.scrollHeight - _result_list.offsetHeight) / _refresh.page_time * _refresh.sleep);
                            if (_distance > 0 && _refresh.row_count < 0) {
                                //當需要滾動的時候，則不需要預先等待時間
                                _refresh.row_count = 0;
                            } else if (_distance == 0) {
                                _distance = 1;
                            }

                            if (_refresh.row_count > 0) {
                                var _old_height = _result_list.scrollTop;
                                _result_list.scrollTop = _refresh.row_count;
                                if (_old_height == _result_list.scrollTop) {
                                    _refresh.row_count = 0 - _refresh.page_time / _refresh.sleep; //換頁後delay一段時間才會開始跑(Ex.10*1*0.2 = 2秒後執行)
                                    _result_list.scrollTop = 0;
                                    $timeout(function () {
                                        next();
                                    });
                                } else {
                                    next();
                                }
                            } else {
                                next();
                            }
                            _refresh.row_count += _distance;
                            _refresh.count += dog.sleep;
                        }
                    }
                };
                $scope.codeList = [
                    //派工日期
                    {
                        name: $filter('translate')('IIoT0109.query.fields.WorkDate'), column_name: 'WORKDATE',
                        value_s: new Date(), value_e: new Date(), data_type: 'SE', require: true
                    },
                    { name: $filter('translate')('IIoT0109.query.fields.EquipmentNo'), column_name: 'A.EQUIPMENTNO' },
                    { name: $filter('translate')('IIoT0109.query.fields.LotNo'), column_name: 'A.LOTNO' },
                    { name: $filter('translate')('IIoT0109.query.fields.AreaNo'), column_name: 'D.AREANO' },
                    { name: $filter('translate')('IIoT0109.query.fields.ProductNo'), column_name: 'F.ProductNo' },
                    { name: $filter('translate')('IIoT0109.query.fields.RONO'), column_name: 'G.RONO' }
                ];
                //使初始查詢條件預設為"日期"
                var obj = angular.merge({ date_type: "0" }, $scope.codeList[0]);
                $scope.condition_item = obj;

                $scope.nowDateTime = moment().format('YYYY/MM/DD');
                $scope.dateTimeArray = [];//日期陣列
                $scope.masterList = {};//主查詢
                $scope.detailList = [];//子查詢

                //調整日期格式
                $scope.tableColumnFormatters = {
                    'model.to': function (value, column, row) {
                        if (value && value.format) {
                            return value.format('YYYY/MM/DD');
                        }
                        return value;
                    },
                    'model.from': function (value, column, row) {
                        if (value && value.format) {
                            return value.format('YYYY/MM/DD');
                        }
                        return value;
                    }
                };
                $scope.filterHeader = '<i class="gantt-tree-handle glyphicon" style="top:4px;" ng-class="scope.collapseClass();" ng-click="scope.collapseTrigger();"></i>{{getHeader()}}';
            };

            $scope.back = function () {
                if ($scope.queryMode == 'list-detail') {
                    //$scope.queryMode='list';
                    $scope.detailList = [];
                } else {
                    $scope.$root.hideMenu();
                    $scope.$root.changeProgram('home', true);
                }

            };

            var _report_data = [];
            $scope.search = function (condition, next) {
                $scope.showGanttPanel = true;
                var isShowLoading = true;
                _condition = condition;
                _refresh.condition = $scope.conditionList;
                localStorage.setItem(config.appName + '_RPT_Settings_' + $scope.$root.currentState, JSON.stringify(_refresh));
                $MMWService.sendToServer({
                    uri: 'ServicesSTD.Module_SYS.user_custom_report_data_get',
                    content: {
                        report_id: 'IIoT0109',
                        query_condition_info: condition
                    },
                    success: function (data) {
                        _refresh.condition = data;
                        _report_data = data.report_data;
                        for (var i = 0; i < _report_data.length; i++) {
                            _report_data[i].work_date = _report_data[i].WorkDate;
                        }
                        if (data.report_data.length > 0) {
                            if ($scope.queryMode == 'list-gantt') {
                                $scope.genGantt();
                            }
                        }
                        else {
                            $scope.masterList = {};
                            $rootScope.showAlert($filter('translate')('common.msg.no_data'));
                        }
                        if (next)
                            next();
                    }
                }, isShowLoading);
            };

            $scope.closeDetail = function () {
                $scope.detailList = [];
            };

            function ParseTemp(dataList, parent, _temp) {
                $rootScope.getValueforObj(_temp).forEach(function (item) {
                    var data_item = {
                        name: _uuid(),
                        content: item.name,
                        seq: item.seq,
                        from: item.from,
                        to: item.to,
                        qty: item.qty,
                        is_new: 0
                    };
                    var data_item_2 = {
                        name: _uuid(),
                        content: item.name,
                        seq: item.seq,
                        from: item.from,
                        to: item.to,
                        qty: item.qty,
                        is_new: 1
                    };

                    dataList.push(data_item);
                    if (parent) {
                        parent.children.push(data_item.name);
                        if (item.column_name == 'LotNo') {
                            parent.children.push(data_item_2.name);
                            dataList.push(data_item_2);
                        }

                    }
                    if (item._temp && $rootScope.getValueforObj(item._temp).length > 0) {
                        data_item.children = [];
                        ParseTemp(dataList, data_item, item._temp);
                    }
                    //else {
                    data_item.tasks = [{
                        name: '',
                        color: item.color,
                        from: data_item.from,
                        to: data_item.to,
                        progress: {
                            percent: 0,
                            color: '#F1C232'
                        }
                    }];
                    data_item_2.tasks = [{
                        name: '',
                        color: '#0000CD',
                        from: data_item.from,
                        to: data_item.to,
                        progress: {
                            percent: 0,
                            color: '#F1C232'
                        }
                    }];
                    //}
                });
            }

            $scope.ganttSettings = {
                headers: 'hour',
                datetype: 'work_date',
                datetypes: [
                    { column: 'work_date', name: $filter('translate')('IIoT0109.query.fields.WorkDate'), from: 'work_date', to: 'work_date' },
                    { column: 'plan_date', name: $filter('translate')('IIoT0109.query.fields.PlanDate'), from: 'plot_start_time', to: 'plot_end_time' }
                ],
                ganttGroups: [
                    { column: 'roid', name: $filter('translate')('IIoT0109.query.fields.roid'), color: '#4374ba', isSelect: false, qty: 'Qty', qty_type: 'add' },
                    { column: 'prdid', name: $filter('translate')('IIoT0109.query.fields.prdid'), color: '#AA7700', isSelect: false, qty: 'Qty', qty_type: 'add' },
                    { column: 'MONO', name: $filter('translate')('IIoT0109.query.fields.MoNo'), color: '#BBBB00', isSelect: false, qty: 'Qty', qty_type: 'add' },
                    { column: 'opid', name: $filter('translate')('IIoT0109.query.fields.opid'), color: '#00DD00', isSelect: false, qty: 'Qty', qty_type: 'add' },
                    { column: 'eqpid', name: $filter('translate')('IIoT0109.query.fields.eqpid'), color: '#FFFFFF', isSelect: true, qty: 'Qty', qty_type: 'max' },
                    { column: 'LotNo', name: $filter('translate')('IIoT0109.query.fields.LotNo'), color: '#778899', isSelect: true, qty: 'Qty', qty_type: 'max' }
                ]
            }
            $scope.genGantt = function () {
                var _headers = ['year', 'month', 'week', 'day', 'hour'];
                $scope.queryMode = 'list-gantt';
                $scope.collapseStatus = false;
                if (_report_data.length > 0) {
                    $scope.$root.showLoading();
                    var _datetype = $filter('filter')($scope.ganttSettings.datetypes, { column: $scope.ganttSettings.datetype })[0],
                        _temp = {},
                        _groups = $filter('filter')($scope.ganttSettings.ganttGroups, { isSelect: true });

                    //產生標頭
                    $scope.options.viewScale = $scope.ganttSettings.headers;
                    if ($scope.options.viewScale == 'hour') {
                        $scope.options.headers = ['day', 'hour'];
                        $scope.options.columnWidth = 20;
                    } else if ($scope.options.viewScale == 'day') {
                        $scope.options.headers = ['month', 'day'];
                        $scope.options.columnWidth = 28;
                    } else if ($scope.options.viewScale == 'week') {
                        $scope.options.headers = ['month', 'week'];
                        $scope.options.columnWidth = 56;
                    } else if ($scope.options.viewScale == 'month') {
                        $scope.options.headers = ['year', 'month'];
                        $scope.options.columnWidth = 224;
                    } else if ($scope.options.viewScale == 'year') {
                        $scope.options.headers = ['year'];
                        $scope.options.columnWidth = 300;
                    }

                    _report_data.forEach(function (item) {
                        var _str_var = '';
                        _groups.forEach(function (_group_obj, index) {
                            var _real_var;
                            if (index != 0)
                                _str_var += '.';
                            _str_var += '_temp[item[_groups[' + index + '].column]]';
                            eval('_real_var = ' + _str_var + ';');

                            if (!_real_var) {
                                _real_var = {
                                    name: item[_group_obj.column],
                                    from: moment(item[_datetype.from]).set({ 'hour': 0, 'minute': 0, 'second': 0 }),
                                    to: moment(item[_datetype.to]).set({ 'hour': 23, 'minute': 59, 'second': 59 }),
                                    color: _group_obj.color,
                                    qty: item[_group_obj.qty],
                                    seq: item['op_seq'],
                                    is_new: item.is_new,
                                    column_name: _group_obj.column,
                                    _temp: {}
                                };
                                eval(_str_var + ' = _real_var;');
                            } else {
                                if (_real_var.from.diff(item[_datetype.from]) > 0) {
                                    _real_var.from = moment(item[_datetype.from]).set({ 'hour': 0, 'minute': 0, 'second': 0 });
                                }
                                if (_real_var.to.diff(item[_datetype.to]) < 0) {
                                    _real_var.to = moment(item[_datetype.to]).set({ 'hour': 23, 'minute': 59, 'second': 59 });
                                }
                                if (_group_obj.qty_type == 'max') {
                                    if (_real_var.qty <= item[_group_obj.qty]) {
                                        _real_var.qty = item[_group_obj.qty];
                                    }
                                } else {
                                    _real_var.qty += item[_group_obj.qty];
                                }
                            }
                        });
                    });
                    var _gantt_data = [];
                    ParseTemp(_gantt_data, undefined, _temp);
                    $timeout(function () {
                        $scope.options.maxHeight = document.getElementById('panel_gantt').offsetHeight - 8;
                        $scope.data = _gantt_data;
                    }, 200);
                }
            }
            $scope.$watch(function () {
                return document.getElementById('panel_gantt').offsetHeight - 8;
            }, function (newValue, oldValue) {
                if (newValue !== oldValue) {
                    $scope.options.maxHeight = newValue;
                }
            });

            $scope.registerApi = function (api) {
                api.core.on.ready($scope, function (_api) {
                    $scope.collapseTrigger = function () {
                        $scope.collapseStatus = !$scope.collapseStatus;
                        if ($scope.collapseStatus) {
                            //_api.tree.collapseAll();
                            $scope.$broadcast('angular-ui-tree:collapse-all');
                        } else {
                            //_api.tree.expandAll();
                            $scope.$broadcast('angular-ui-tree:expand-all');
                        }
                    }
                    $scope.collapseClass = function () {
                        if ($scope.collapseStatus) {
                            return 'glyphicon-chevron-right';
                        } else {
                            return 'glyphicon-chevron-down';
                        }
                    }
                    _api.tree.on.collapsed($scope, function (row, collapsed) {
                        if (collapsed._collapsed) {
                            //關起來
                        } else {
                            //打開
                            $scope.collapseStatus = false;
                        }
                    });
                    _api.data.on.change($scope, (newData, OldData) => {
                        $scope.$root.hideLoading();
                    });
                });
            }

            function _uuid() {
                var d = Date.now();
                if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
                    d += performance.now(); //use high-precision timer if available
                }
                return 'xxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                    var r = (d + Math.random() * 16) % 16 | 0;
                    d = Math.floor(d / 16);
                    return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
                });
            }

            $scope.ganttSetting = function () {
                var options = {};
                options.settings = $scope.ganttSettings;
                $mdDialog.serviceDialog('IIoT0109GanttSetting',
                    angular.extend({}, options),
                    function (settings) {
                        $scope.ganttSettings = settings;
                        _refresh.time = settings.refresh.time;
                        _refresh.is_start = settings.refresh.is_start;
                        $scope.genGantt();
                        localStorage.setItem(config.appName + '_RPT_Settings_' + $scope.$root.currentState, JSON.stringify(_refresh));
                        _refresh.sleep = settings.refresh.time;
                        if (!$WatchDogService.isStart && _refresh.is_start == 'Y') {
                            $scope.isClose = true;
                            $WatchDogService.startWatch(dog, true);
                        } else if (_refresh.is_start == 'N') {
                            $WatchDogService.stopWatch();
                        }
                    });
            }

            //以下為C00.html
            $scope.default_modeList = [
                { name: $filter('translate')('common.report.condition.equal'), code: '0' },
                { name: $filter('translate')('common.report.condition.nequal'), code: '1' },
                { name: $filter('translate')('common.report.condition.contain'), code: '2' },
                { name: $filter('translate')('common.report.condition.ncontain'), code: '3' },
                { name: $filter('translate')('common.report.condition.exceed-equal'), code: '4' },
                { name: $filter('translate')('common.report.condition.less-equal'), code: '5' },
                { name: $filter('translate')('common.report.condition.exceed'), code: '6' },
                { name: $filter('translate')('common.report.condition.less'), code: '7' }
            ];

            function GetDefaultCondition(newVals) {
                //20181121 modify bu Dustdusk for M#: 沒有設定必填條件，則抓第一筆當預設條件
                var item = angular.merge({}, newVals[0]);
                //20180927 modify by Dustdusk for 選完欄位後增加預設值
                if (item.data_type == 'SE') {
                    $scope.changeDate(item, 0);
                } else {
                    if (item.modeList == undefined || item.modeList.length == 0) {
                        item.modeList = [];
                        item.modeList = default_modeList;
                    }
                    item.query_name = item.modeList[0].name;
                    item.query_mode = item.modeList[0].code;
                }
                $scope.condition_item = item;
            };

            //設定查詢畫面的"欄位"有哪些
            $scope.LoadCodeList = function (item) {
                /*if($scope.conditionList.length == 0){
                    if($scope.codeList && $scope.codeList.length > 0){
                        GetDefaultCondition($scope.codeList);
                    }
                }*/
                $rootScope.showSelect({
                    title: $filter('translate')('common.report.condition_fields'),
                    order: 'order',
                    label: 'name',
                    code: 'column_name',
                    selectCode: item.column_name,
                    list: $scope.codeList,
                    confirm: function (selectItem, dialog) {
                        item.modeList = [];
                        item.query_name = undefined;
                        item.query_mode = undefined;
                        item.data_type = undefined;
                        item.value = undefined;
                        item.require = undefined;
                        item.column_query = undefined;
                        item = angular.extend(item, selectItem);
                        item.value = selectItem.default_value;
                        if (item.data_type == 'SE') {
                            $scope.changeDate(item, 0);
                        } else {
                            //20180927 modify by Dustdusk for 選完欄位後增加預設值
                            if (item.modeList && item.modeList.length > 0) {

                            } else {
                                item.modeList = $scope.default_modeList;
                            }
                            //20200730 modify by Dustdusk for M#: 增加預設條件功能
                            var _temp_mode = $filter('filter')(item.modeList, { code: item.condoperand });
                            if (_temp_mode && _temp_mode.length > 0) {
                                item.query_name = _temp_mode[0].name;
                                item.query_mode = _temp_mode[0].code;
                            } else {
                                item.query_name = item.modeList[0].name;
                                item.query_mode = item.modeList[0].code;
                            }
                            $scope.condition_item = item;
                        }
                        dialog.hide();
                    }
                });
            }
            $scope.condition_item = { column_name: '', query_mode: '', data_type: '' };
            $scope.addCondition = function (isForce) {
                var condition = angular.merge({}, $scope.condition_item);

                if (condition.data_type == 'SE') {
                    condition.desc = condition.name + ' ' + moment(condition.value_s).format('YYYY/MM/DD') + '~' + moment(condition.value_e).format('YYYY/MM/DD');
                    //20190712 modify by Dustdusk for M#59711: 增加檢查防止查相同的日期
                    if ($filter('filter')($scope.conditionList, { desc: condition.desc }).length == 0) {
                        $scope.conditionList.push(condition);
                    }
                } else {
                    if (condition.column_name != '' && condition.query_mode != '' && $scope.condition_item.value && $scope.condition_item.value != '') {
                        if (condition.data_type == 'D') {
                            condition.desc = condition.name + ' ' + condition.query_name + ' ' + moment(condition.value).format('YYYY/MM/DD');
                            //scope.condition_item.value = new Date();
                            $scope.condition_item.value = undefined;
                        } else {
                            condition.desc = condition.name + ' ' + condition.query_name + ' ' + condition.value;
                            //20190606 modify by Dustdusk for M#58418: 當全部條件都刪除的時候自動載入預設值 or 第一筆
                            $scope.condition_item.value = '';
                            //20190905 modify by Dustdusk for M#: 清除下拉選單的值
                            $scope.condition_item.name_value = '';
                        }
                        $scope.conditionList.push(condition);
                        //20190606 modify by Dustdusk for M#58418: 當全部條件都刪除的時候自動載入預設值 or 第一筆
                        //GetDefaultCondition(scope.codeList);
                    } else if (!isForce) {
                        $rootScope.showAlert($filter('translate')('C00.msg.condition_empty'));
                    }
                }
            };

            $scope.conditionList = [];
            // $scope.$watch('codeList', function(newVals, oldVals){
            //     if($scope.conditionList.length == 0){
            //         if(newVals && newVals.length > 0){
            //             GetDefaultCondition(newVals);
            //         }
            //     }
            // });

            $scope.selectCondition = function (index, item) {
                $scope.isClose = false;
                $scope.condition_item = item;
                $scope.conditionList.splice(index, 1);
            };

            $scope.removeCondition = function (event, index) {
                event.stopPropagation();
                $scope.conditionList.splice(index, 1);
                if ($scope.conditionList && $scope.conditionList.length == 0) {
                    $scope.isClose = false;
                    GetDefaultCondition($scope.codeList);
                }
            };

            $scope.loadTypeList = function (item) {
                if (item.modeList) {
                    $rootScope.showSelect({
                        title: $filter('translate')('common.condition_title'),
                        label: 'name',
                        code: 'code',
                        selectCode: item.code,
                        list: item.modeList,
                        confirm: function (selectItem, dialog) {
                            item.query_name = selectItem.name;
                            item.query_mode = selectItem.code;
                            dialog.hide();
                        }
                    });
                }
            };

            $scope.changeDate = function (item, date) {
                item.value_s = new Date();
                item.value_e = moment(new Date()).add(date, 'days').toDate();
                item.date_type = date;
            };

            $scope.checkValue = function (item, select_check_value) {
                if (item.multiple == true) {
                    select_check_value.checked = !select_check_value.checked;
                } else {
                    item.check_values.forEach(function (check_value) {
                        check_value.checked = false;
                    });
                    select_check_value.checked = true;
                }
            };

            $scope.checkCondition = function (conditon) {
                var _require_condition = $filter('filter')($scope.codeList, { require: true }),
                    _require_s_condition = $filter('filter')(conditon, { require: true });

                if (_require_condition.length > 0 && _require_s_condition.length == 0) {
                    var _condition_name = '';
                    _require_condition.forEach(function (condition, index) {
                        if (index != 0)
                            _condition_name += '、';
                        _condition_name += condition.name;
                    });
                    $rootScope.showAlert($filter('translate')('C00.msg.condition_require') + _condition_name);
                    return false;
                }
                return true;
            };

            $scope.loadSelect = function (item) {
                if (item.datasource_format_info) {
                    if (item.datasource_format_info.data_info && item.datasource_format_info.data_info.length > 0) {
                        var header = [], filterColumns = [];
                        item.datasource_format_info.column_info.forEach(function (column, index) {
                            header.push({ label: column, code: index });
                            filterColumns[index] = undefined;
                        });
                        $rootScope.showQueryList({
                            key: item.datasource_format_info.iselectd_filed,
                            filterColumns: filterColumns,
                            pageRecord: 50,
                            header: header,
                            query: function (conditions, feedback) {
                                feedback(item.datasource_format_info.data_info);
                            },
                            selectCode: item.value || '',
                            confirm: function (selectItem, dialog) {
                                item.value = selectItem[item.datasource_format_info.iselectd_filed] + '';
                                item.name_value = selectItem[item.datasource_format_info.iselectd_filed] + '';
                                dialog.hide();
                            }
                        });
                    }
                }
            };

            $scope.beforeSearch = function (options) {
                if (!options)
                    options = { isWarning: true };
                $scope.addCondition(true);
                var condition = $rootScope.genConditioninfo();
                if ($scope.checkCondition(condition)) {
                    if (!options.isWarning || condition.length > 0) {
                        $scope.isClose = true;
                        if (options.search) {
                            options.search(condition, options.callback);
                        } else if ($scope.search) {
                            $scope.search(condition, options.callback);
                        }
                    } else if ($scope.C00_require_condition) {
                        //請輸入查詢條件
                        $rootScope.showAlert($filter('translate')('common.msg.no_report_condition'));
                    } else {
                        $rootScope.showConfirm($filter('translate')('common.msg.no_report_condition_confirm'), function (dialog) {
                            dialog.hide();
                            if (options.search) {
                                options.search(condition, options.callback);
                            } else if ($scope.search) {
                                $scope.search(condition, options.callback);
                            }
                        });
                    }
                }
            };

            //產生查詢條件
            $rootScope.genConditioninfo = function () {
                var query_condition_info = [],
                    query_conditoin;
                if ($scope.conditionList && $scope.conditionList.length > 0) {
                    $scope.conditionList.forEach(function (condition) {
                        //20180927 modify by Dustdusk for M#50923: 防止沒輸入條件
                        condition.column_name = condition.column_name || '';
                        condition.query_mode = condition.query_mode || '';
                        condition.value = condition.value || '';
                        if (condition.data_type == 'SE') {
                            //起日
                            query_conditoin = {};
                            query_conditoin.column_name = condition.column_name;
                            query_conditoin.require = condition.require;
                            query_conditoin.query_mode = 4;
                            query_conditoin.merge_condition_model = 'AND';
                            // 20190521 modify by Dustdusk for M#57628: 修正報表查詢的時間起迄不被時間影響
                            query_conditoin.value = moment(condition.value_s).format('YYYY-MM-DD') + ' 00:00:00';
                            query_condition_info.push(query_conditoin);
                            //訖日
                            query_conditoin = {};
                            query_conditoin.column_name = condition.column_name;
                            query_conditoin.require = condition.require;
                            query_conditoin.query_mode = 5;
                            query_conditoin.merge_condition_model = 'AND';
                            // 20190521 modify by Dustdusk for M#57628: 修正報表查詢的時間起迄不被時間影響
                            query_conditoin.value = moment(condition.value_e).format('YYYY-MM-DD') + ' 23:59:59';
                            query_condition_info.push(query_conditoin);

                        } else if (condition.data_type == 'C') {
                            query_conditoin = {};

                            query_conditoin.column_name = condition.column_name;
                            query_conditoin.require = condition.require;
                            query_conditoin.query_mode = 0;
                            query_conditoin.merge_condition_model = 'AND';
                            condition.check_values.forEach(function (value) {
                                if (value.checked) {
                                    query_conditoin.value = value.value;
                                }
                            });
                            if (query_conditoin.value && query_conditoin.value != '') {
                                query_condition_info.push(query_conditoin);
                            }
                        } else if (condition.column_name != '' && condition.query_mode != '' && condition.value && condition.value != '') {
                            query_conditoin = {};
                            query_conditoin.column_name = condition.column_name;
                            query_conditoin.require = condition.require;
                            query_conditoin.query_mode = condition.query_mode;
                            query_conditoin.merge_condition_model = 'AND';

                            if (condition.data_type == 'D') {
                                query_conditoin.value = moment(condition.value).format('YYYY-MM-DD');
                            } else {
                                //20190125 modify by Dustdusk for M#: 查詢條件為包含時自動增加前後%
                                if (condition.data_type != 'N' && (query_conditoin.query_mode == '2' || query_conditoin.query_mode == '3')) {
                                    query_conditoin.value = '%' + condition.value + '%';
                                } else {
                                    query_conditoin.value = condition.value;
                                }

                            }
                            query_condition_info.push(query_conditoin);
                        }
                    });
                }
                return query_condition_info;
            };
        }
    ];
});
